webdriver中的等待

您所在的位置:网站首页 online presence的类型 webdriver中的等待

webdriver中的等待

2023-08-15 19:55| 来源: 网络整理| 查看: 265

webdriver中的等待——主要讲解WebDriverWait()

抬眼已是半生: # 9、以下四个条件判断元素是否被选中, # 第一个条件传入WebElement对象, # 第二个传入locator元组 # 第三个传入WebElement对象以及状态,相等返回True,否则返回False # 第四个传入locator以及状态,相等返回True,否则返回False # el_ = self.driver.find_element(By.ID, 'su') # el = wait.until(EC.element_to_be_selected(el_), message='11111') # el = wait.until(EC.element_located_to_be_selected((By.ID, 'su')), message='11111') # el = wait.until(EC.element_selection_state_to_be((By.ID, 'su'), '1'), message='11111') # el = wait.until(EC.element_located_selection_state_to_be((By.ID, 'su'), '0'), message='11111') # 10、判断一个元素是否仍在DOM中,传入WebElement对象,可以判断页面是否刷新了,如果还是存在则会抛出超时异常 el_ = self.driver.find_element(By.ID, 'su') el = wait.until(EC.staleness_of(el_), message='11111')

webdriver中的等待——主要讲解WebDriverWait()

抬眼已是半生: # 5、以下两个条件判断某段文本是否出现在某元素中,一个判断元素的text,一个判断元素的value, 返回布尔值 # el = wait.until(EC.text_to_be_present_in_element((By.ID, 's-top-left'), '更多'), message='11111') # el = wait.until(EC.text_to_be_present_in_element_value((By.ID, 'su'), '百度'), message='11111') # 6、以下条件判断frame是否可切入,可传入locator元组或者直接传入定位方式:id、name、index或WebElement # el = wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'su')), message='11111') # 7、判断是否有alert出现,有则返回alert元素,否则返回false # el = wait.until(EC.alert_is_present(), message='11111') # 8、以下条件判断元素是否可点击,传入locator el = wait.until(EC.element_to_be_clickable((By.ID, 'su')), message='11111')

webdriver中的等待——主要讲解WebDriverWait()

抬眼已是半生: 一个一个试了一下,有个标错了: # 1、显示等待, wait = WebDriverWait(driver=self.driver, timeout=timeout, poll_frequency=poll_frequency) # el = wait.until(lambda driver: driver.find_element(By.ID, 'su')) # el = wait.until_not(lambda driver: driver.find_element(By.ID, 'su')) # 2、判断当前页面的 title 是否完全等于(==)预期字符串,返回布尔值 # el = wait.until(EC.title_is('百度一下,你就知道'), message='11111') # 判断当前页面的 title 是否包含预期字符串,返回布尔值 # el = wait.until(EC.title_contains('百度一下'), message='11111') # 3、判断元素是否可见(可见代表元素非隐藏,并且元素宽和高都不等于 0), 返回一个元素 # el = wait.until(EC.visibility_of_element_located((By.ID, 'su')), message='11111') # 判断元素不可见,如果是可见元素会抛出超时异常 # el = wait.until(EC.invisibility_of_element_located((By.ID, 'su')), message='11111') # 同上一方法,只是上一方法参数为locator,这个方法参数是 定位后的元素 返回一个元素 # el_ = self.driver.find_element(By.ID, 'su') # el = wait.until(EC.visibility_of(el_), message='11111')

webdriver中的等待——主要讲解WebDriverWait()

柳暗花明又一cun: 真不错表情包

Pycharm设置代码模板

好汤圆: 分享技术,不错哦



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3